<?php
namespace app\admin\controller;

use app\main\controller\BaseController;
use app\admin\model\Role;

class RoleController extends BaseController {
    protected $model;
    public function __construct() {
        parent::__construct();
        $this->model = new Role();
    }
    public function indexAction() {
        $items = $this->model->getAll();
        $this->render('view/user/index', ['items'=>$items]);
    }
    public function addAction() {
        if($_SERVER['REQUEST_METHOD']==='POST') {
            $this->model->insert($_POST);
            header('Location: /main/role/index'); exit;
        }
        $this->render('view/user/form');
    }
    public function editAction($id) {
        $itemData = $this->model->get($id);
        if($_SERVER['REQUEST_METHOD']==='POST') {
            $this->model->update($id, $_POST);
            header('Location: /main/role/index'); exit;
        }
        $this->render('view/user/form', ['item'=>$itemData]);
    }
    public function deleteAction($id) {
        $this->model->delete($id);
        header('Location: /main/role/index'); exit;
    }
}
